package net.pulseproject.commons.gui;

import java.awt.event.ActionEvent;

import net.pulseproject.commons.util.StringUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class SafeActionListenerImpl implements SafeActionListener {
	
	private static final Log LOG = LogFactory.getLog(SafeActionListenerImpl.class);
	
	@Override public final void actionPerformed(final ActionEvent event) {
		try {
			this.action(event);
		} catch(final Exception e) {
			try {
				this.onActionThrewException(event, e);
			} catch(final Exception e2) {
				LOG.error("Could not handle original exception '" + e.getMessage() + "':" +
						StringUtil.exceptionToString(e), e2);
			}
		}
	}

}
